package main

import "fmt"

/*** 函数-递归调用 ***/
func main() {
	test01(10)
	fmt.Println("===== recursive =====")
	a := test02(100)
	fmt.Println("a=", a)
}

//递归01
func test01(a int) {
	a = a - 1
	fmt.Println("a=", a)
	if a < 1 { //归递调用必须要有中断，否则要内存溢出
		return
	}
	test01(a)
}

//递归02
func test02(a int) (ret int) {
	if a == 1 { //中断
		return 1
	}
	ret = test02(a-1) + a
	fmt.Println("ret=", ret)
	return
}
